package tianqi.service.product.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import tianqi.Dao.product.ProductDetailDao;
import tianqi.entity.ProductCon;
import tianqi.entity.ShareOrder;
import tianqi.service.product.ProductdetailService;

@Service
public class ProductdetailServiceImpl implements ProductdetailService {
	
	@Autowired
	private ProductDetailDao productDetailDao;
	
	@Override
	public String queryDetailById(String p,Model m) {
		
		ProductCon pp=new ProductCon();
		pp.setIdPro(p);
		ProductCon queryDetailById = productDetailDao.queryDetailById(pp);
		m.addAttribute("p", queryDetailById);	
		Map<String,String> map=new HashMap<String,String>(); 
		map.put("col", queryDetailById.getImgName());
		map.put("tab", queryDetailById.getTableName());
		map.put("idcol", queryDetailById.getColumn1());
		map.put("id", "'"+queryDetailById.getIdPro()+"'");
		String queryDetailImg = productDetailDao.queryDetailImg(map);
		List<ShareOrder> querySoById = productDetailDao.querySoById(pp);
		for (ShareOrder shareOrder : querySoById) {
			if(shareOrder.getSoImg().indexOf(";")>0){
				shareOrder.setSplit(shareOrder.getSoImg().split(";"));
			}else {
				shareOrder.setSplit(new String[]{shareOrder.getSoImg()});
			}
		}
		m.addAttribute("sos", querySoById);
		
		m.addAttribute("img", queryDetailImg);
		
		return "youger_xq";
	}
	
}
